# load required libraries
library(tidyverse)
library(langcog) # source: https://github.com/langcog/langcog-package
library(psych)
library(lme4)
library(cowplot)
# set theme for ggplots
theme_set(theme_bw())
d_all <- bind_rows(d_us_ad %>% rownames_to_column("subid"),
d_us_ch %>% rownames_to_column("subid"),
d_gh_ad %>% rownames_to_column("subid"),
d_gh_ch_fante %>% rownames_to_column("subid"),
d_th_ad %>% rownames_to_column("subid"),
d_th_ch %>% rownames_to_column("subid"),
d_vt_ad %>% rownames_to_column("subid"),
d_vt_ch %>% rownames_to_column("subid")) %>%
column_to_rownames("subid")
We’ll extract 4 factors from all samples, to keep things simple.
efa_us_ad_4 <- fa(d_us_ad, nfactors = 4, rotate = "varimax")
efa_us_ch_4 <- fa(d_us_ch, nfactors = 4, rotate = "varimax")
efa_gh_ad_4 <- fa(d_gh_ad, nfactors = 4, rotate = "varimax")
efa_gh_ch_4 <- fa(d_gh_ch_fante, nfactors = 4, rotate = "varimax")
efa_th_ad_4 <- fa(d_th_ad, nfactors = 4, rotate = "varimax")
efa_th_ch_4 <- fa(d_th_ch, nfactors = 4, rotate = "varimax")
efa_vt_ad_4 <- fa(d_vt_ad, nfactors = 4, rotate = "varimax")
efa_vt_ch_4 <- fa(d_vt_ch, nfactors = 4, rotate = "varimax")
plot_us_ad_4 <- heatmap_fun(efa_us_ad_4) +
guides(fill = "none") +
labs(x = "US: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_us_ch_4 <- heatmap_fun(efa_us_ch_4) +
guides(fill = "none") +
labs(x = "US: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_gh_ad_4 <- heatmap_fun(efa_gh_ad_4) +
guides(fill = "none") +
labs(x = "Ghana: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_gh_ch_4 <- heatmap_fun(efa_gh_ch_4) +
guides(fill = "none") +
labs(x = "Ghana: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_th_ad_4 <- heatmap_fun(efa_th_ad_4) +
guides(fill = "none") +
labs(x = "Thailand: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_th_ch_4 <- heatmap_fun(efa_th_ch_4) +
guides(fill = "none") +
labs(x = "Thailand: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_vt_ad_4 <- heatmap_fun(efa_vt_ad_4) +
guides(fill = "none") +
labs(x = "Vanuatu: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_vt_ch_4 <- heatmap_fun(efa_vt_ch_4) +
guides(fill = "none") +
labs(x = "Vanuatu: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_grid(plot_us_ad_4, plot_us_ch_4,
plot_gh_ad_4, plot_gh_ch_4,
plot_th_ad_4, plot_th_ch_4,
plot_vt_ad_4, plot_vt_ch_4,
ncol = 2, labels = "AUTO")
We’ll extract 3 factors from all samples, to keep things simple.
efa_us_ad_3 <- fa(d_us_ad, nfactors = 3, rotate = "varimax")
efa_us_ch_3 <- fa(d_us_ch, nfactors = 3, rotate = "varimax")
efa_gh_ad_3 <- fa(d_gh_ad, nfactors = 3, rotate = "varimax")
efa_gh_ch_3 <- fa(d_gh_ch_fante, nfactors = 3, rotate = "varimax")
efa_th_ad_3 <- fa(d_th_ad, nfactors = 3, rotate = "varimax")
efa_th_ch_3 <- fa(d_th_ch, nfactors = 3, rotate = "varimax")
efa_vt_ad_3 <- fa(d_vt_ad, nfactors = 3, rotate = "varimax")
efa_vt_ch_3 <- fa(d_vt_ch, nfactors = 3, rotate = "varimax")
plot_us_ad_3 <- heatmap_fun(efa_us_ad_3) +
guides(fill = "none") +
labs(x = "US: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_us_ch_3 <- heatmap_fun(efa_us_ch_3) +
guides(fill = "none") +
labs(x = "US: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_gh_ad_3 <- heatmap_fun(efa_gh_ad_3) +
guides(fill = "none") +
labs(x = "Ghana: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_gh_ch_3 <- heatmap_fun(efa_gh_ch_3) +
guides(fill = "none") +
labs(x = "Ghana: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_th_ad_3 <- heatmap_fun(efa_th_ad_3) +
guides(fill = "none") +
labs(x = "Thailand: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_th_ch_3 <- heatmap_fun(efa_th_ch_3) +
guides(fill = "none") +
labs(x = "Thailand: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_vt_ad_3 <- heatmap_fun(efa_vt_ad_3) +
guides(fill = "none") +
labs(x = "Vanuatu: adults") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_vt_ch_3 <- heatmap_fun(efa_vt_ch_3) +
guides(fill = "none") +
labs(x = "Vanuatu: children") +
theme(axis.title.x = element_text(hjust = 0))
Joining, by = "capacity"
Joining, by = "factor"
plot_grid(plot_us_ad_3, plot_us_ch_3,
plot_gh_ad_3, plot_gh_ch_3,
plot_th_ad_3, plot_th_ch_3,
plot_vt_ad_3, plot_vt_ch_3,
ncol = 2, labels = "AUTO")
paste("US adults:", nrow(d_us_ad))
[1] "US adults: 127"
paste("US children:", nrow(d_us_ch))
[1] "US children: 117"
paste("GH adults:", nrow(d_gh_ad))
[1] "GH adults: 150"
paste("GH children:", nrow(d_gh_ch))
[1] "GH children: 149"
paste("TH adults:", nrow(d_th_ad))
[1] "TH adults: 150"
paste("TH children:", nrow(d_th_ch))
[1] "TH children: 152"
paste("VT adults:", nrow(d_vt_ad))
[1] "VT adults: 164"
paste("VT children:", nrow(d_vt_ch))
[1] "VT children: 169"
paste("Non-US:", sum(nrow(d_gh_ad), nrow(d_gh_ch),
nrow(d_th_ad), nrow(d_th_ch),
nrow(d_vt_ad), nrow(d_vt_ch)))
[1] "Non-US: 934"
paste0("Adults: n = ", min(nrow(d_us_ad), nrow(d_gh_ad), nrow(d_th_ad), nrow(d_vt_ad)), "-", max(nrow(d_us_ad), nrow(d_gh_ad), nrow(d_th_ad), nrow(d_vt_ad)), "; total N = ", sum(nrow(d_us_ad), nrow(d_gh_ad), nrow(d_th_ad), nrow(d_vt_ad)))
[1] "Adults: n = 127-164; total N = 591"
paste0("Children: n = ", min(nrow(d_us_ch), nrow(d_gh_ch), nrow(d_th_ch), nrow(d_vt_ch)), "-", max(nrow(d_us_ch), nrow(d_gh_ch), nrow(d_th_ch), nrow(d_vt_ch)), "; total N = ", sum(nrow(d_us_ch), nrow(d_gh_ch), nrow(d_th_ch), nrow(d_vt_ch)))
[1] "Children: n = 117-169; total N = 587"
d_all %>%
rownames_to_column("site_age_subid_target_character") %>%
mutate(site_age_subid_target_character = gsub("cell phones", "cellphones", site_age_subid_target_character)) %>%
separate(site_age_subid_target_character, into = c("site", "age", "subid", "target", "character")) %>%
count(site, age, character) %>%
spread(character, n)
d_all %>%
rownames_to_column("site_age_subid_target_character") %>%
mutate(site_age_subid_target_character = gsub("cell phones", "cellphones", site_age_subid_target_character)) %>%
separate(site_age_subid_target_character, into = c("site", "age", "subid", "target", "character")) %>%
filter(is.na(character) | character == "NA")